package org.hs.phd.odi.tracking;

import java.awt.Rectangle;

import org.hs.phd.common.framesource.FolderFrameSource;
import org.hs.phd.common.framesource.FrameSource;
import org.hs.phd.odi.tracking.tracker.TrackerUtils;
import org.hs.phd.odi.tracking.tracker.comaniciu.ComaniciuTracker;
import org.hs.phd.odi.tracking.tracker.histogram.Weighted3DHistogram;
import org.hs.phd.odi.tracking.tracker.kernel.EpanechnikovKernel;
import org.hs.phd.odi.tracking.tracker.similaritymeasure.BhattacharyaCoefficientSimilartyMeasure;
import org.hs.phd.odi.tracking.tracker.trackwindow.RegularGridTrackWindow;


public class TrackingDemo1 {

    public static void main(String[] args) throws Exception{

        ComaniciuTracker tracker = new ComaniciuTracker(new Weighted3DHistogram(32, 32, 16, new EpanechnikovKernel()), 
				new BhattacharyaCoefficientSimilartyMeasure(), new RegularGridTrackWindow());
        tracker.setVisulizationEnabled(true);
        tracker.setVisualizationWaitMillis(30);

        //FrameSource frameSource = initBlackCarOnTopMiddle(tracker);
        //FrameSource frameSource = initBrownCarOnLeft(tracker);
        FrameSource frameSource = initWhiteCarOnLeft(tracker);
        
        while( true ){
        	tracker.track(frameSource.loadNextFrame().getFrameImage());
        }

    }

	private static FrameSource initBlackCarOnTopMiddle(ComaniciuTracker tracker) {
		return initTracker(tracker, 4151, new Rectangle(241, 58, 32, 13));
	}

	private static FrameSource initBrownCarOnLeft(ComaniciuTracker tracker) {
		return initTracker(tracker, 4196, new Rectangle(67, 155, 25, 30));
	}

	private static FrameSource initWhiteCarOnLeft(ComaniciuTracker tracker) {
		return initTracker(tracker, 4380, new Rectangle(163, 79, 30, 20));
	}

	private static FrameSource initTracker(ComaniciuTracker tracker, int startFrameNo, Rectangle trackStartRect) {
		FrameSource frameSource = new FolderFrameSource(
                "D:\\Hakan_PhD\\Data\\OwnData\\KAYIT_20111123\\KAYIT_dia6_exp512\\renamed\\Image",
                ".jpg", startFrameNo);
        frameSource.setROI(new Rectangle(205, 85, 1019, 874));
        
        
		tracker.init(TrackerUtils.getAsPolygon(trackStartRect), frameSource.loadNextFrame().getFrameImage());
		return frameSource;
	}

}
